Micron Document
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| SparkN0de-git | SparkN0de |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Displaying Raw • Download


meshchatx/src/frontend/components/messages/conversationScroll.js 5fa79d363bcbbb6c8fa7d6f26ee429eaa099a7ab (5fa79d36) Text, 3.31 KB

Tff7b72export Tff7b72const Te6edf3SCROLL_BOTTOM_EPS_PX Tff7b72= T79c0ff8Tb4b4b4;

Tff7b72export Tff7b72const Te6edf3LOAD_PREVIOUS_SCROLL_EDGE_PX Tff7b72= T79c0ff500Tb4b4b4;

T8b949e/**
* The message list uses `flex-col-reverse` on the inner wrapper; scrollTop is 0 at the visual bottom
* (newest messages) and increases toward older history.
* @param {Element} container
* @returns {boolean}
*/
Tff7b72export Tff7b72function Te6edf3isScrollColumnReverseTb4b4b4(Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72const Te6edf3inner Tff7b72= Te6edf3containerTff7b72?Tb4b4b4.Te6edf3firstElementChildTb4b4b4;
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3innerTb4b4b4) Tb4b4b4{
Tff7b72return Tff7b72falseTb4b4b4;
Tb4b4b4}
Tff7b72try Tb4b4b4{
Tff7b72return Te6edf3getComputedStyleTb4b4b4(Te6edf3innerTb4b4b4)Tb4b4b4.Te6edf3flexDirection Tff7b72=== Ta5d6ff"column-reverse"Tb4b4b4;
Tb4b4b4} Tff7b72catch Tb4b4b4{
Tff7b72return Tff7b72falseTb4b4b4;
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Maximum valid scrollTop for a scroll container.
* @param {Element} container
* @returns {number}
*/
Tff7b72export Tff7b72function Te6edf3maxScrollTopTb4b4b4(Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72return T79c0ff0Tb4b4b4;
Tb4b4b4}
Tff7b72return Tffa657MathTb4b4b4.Te6edf3maxTb4b4b4(T79c0ff0Tb4b4b4, Te6edf3containerTb4b4b4.Te6edf3scrollHeight Tff7b72- Te6edf3containerTb4b4b4.Te6edf3clientHeightTb4b4b4)Tb4b4b4;
Tb4b4b4}

T8b949e/**
* Whether the viewport is within thresholdPx of the visual bottom (newest messages).
* @param {Element} container
* @param {number} [thresholdPx]
* @returns {boolean}
*/
Tff7b72export Tff7b72function Te6edf3isNearBottomTb4b4b4(Te6edf3containerTb4b4b4, Te6edf3thresholdPx Tff7b72= Te6edf3SCROLL_BOTTOM_EPS_PXTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72return Tff7b72trueTb4b4b4;
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3isScrollColumnReverseTb4b4b4(Te6edf3containerTb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72return Te6edf3containerTb4b4b4.Te6edf3scrollTop Tff7b72<= Te6edf3thresholdPxTb4b4b4;
Tb4b4b4}
Tff7b72const Te6edf3max Tff7b72= Te6edf3maxScrollTopTb4b4b4(Te6edf3containerTb4b4b4)Tb4b4b4;
Tff7b72return Te6edf3max Tff7b72- Te6edf3containerTb4b4b4.Te6edf3scrollTop Tff7b72<= Te6edf3thresholdPxTb4b4b4;
Tb4b4b4}

T8b949e/**
* Sets scroll position to the visual bottom (newest messages).
* @param {Element} container
*/
Tff7b72export Tff7b72function Te6edf3scrollContainerToBottomTb4b4b4(Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72returnTb4b4b4;
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3isScrollColumnReverseTb4b4b4(Te6edf3containerTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3containerTb4b4b4.Te6edf3scrollTop Tff7b72= T79c0ff0Tb4b4b4;
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3containerTb4b4b4.Te6edf3scrollTop Tff7b72= Te6edf3maxScrollTopTb4b4b4(Te6edf3containerTb4b4b4)Tb4b4b4;
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Clears stale scroll position when reusing the same scroll element for another thread.
* `scrollMessagesToBottom` / `scrollContainerToBottom` run after content is mounted.
* @param {Element | null | undefined} container
*/
Tff7b72export Tff7b72function Te6edf3resetMessagesScrollSurfaceTb4b4b4(Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72returnTb4b4b4;
Tb4b4b4}
Te6edf3containerTb4b4b4.Te6edf3scrollTop Tff7b72= T79c0ff0Tb4b4b4;
Tb4b4b4}

T8b949e/**
* When the scroll area has no inner content yet, `isScrollColumnReverse` is false and
* `isNearBottom` is misleading (empty scroller looks "at bottom"). Do not use it to settle.
* @param {Element | null | undefined} container
* @returns {boolean}
*/
Tff7b72export Tff7b72function Te6edf3canTrustScrollNearBottomHeuristicTb4b4b4(Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72return Tffa657BooleanTb4b4b4(Te6edf3containerTff7b72?Tb4b4b4.Te6edf3firstElementChildTb4b4b4)Tb4b4b4;
Tb4b4b4}

T8b949e/**
* Whether the user has scrolled into the region where older messages should be loaded.
* @param {Element} container
* @returns {boolean}
*/
Tff7b72export Tff7b72function Te6edf3shouldLoadPreviousMessagesTb4b4b4(Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3containerTb4b4b4) Tb4b4b4{
Tff7b72return Tff7b72falseTb4b4b4;
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3isScrollColumnReverseTb4b4b4(Te6edf3containerTb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72const Te6edf3max Tff7b72= Te6edf3maxScrollTopTb4b4b4(Te6edf3containerTb4b4b4)Tb4b4b4;
Tff7b72if Tb4b4b4(Te6edf3max Tff7b72<= T79c0ff0Tb4b4b4) Tb4b4b4{
Tff7b72return Tff7b72falseTb4b4b4;
Tb4b4b4}
Tff7b72const Te6edf3st Tff7b72= Te6edf3containerTb4b4b4.Te6edf3scrollTopTb4b4b4;
Tff7b72if Tb4b4b4(Te6edf3max Tff7b72- Te6edf3st Tff7b72> Te6edf3LOAD_PREVIOUS_SCROLL_EDGE_PXTb4b4b4) Tb4b4b4{
Tff7b72return Tff7b72falseTb4b4b4;
Tb4b4b4}
T8b949e// Short threads: `max - st` is small even at the visual bottom (newest), because `max` itself
T8b949e// is small. Require leaving the bottom band so we do not auto-load in a loop while pinned there.
Tff7b72return Te6edf3st Tff7b72> Te6edf3SCROLL_BOTTOM_EPS_PXTb4b4b4;
Tb4b4b4}
Tff7b72return Te6edf3containerTb4b4b4.Te6edf3scrollTop Tff7b72<= Te6edf3LOAD_PREVIOUS_SCROLL_EDGE_PXTb4b4b4;
Tb4b4b4}


──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────